package org.gwt.project.tools.quickfix;

import java.util.Collections;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;

public class ConfigureBuildPath implements IMarkerResolution {
	
	private String label;
	
	public ConfigureBuildPath() {
		this("Configure build path...");
	}
	
	public ConfigureBuildPath(String label) {
		this.label = label;
	}

	@Override
	public String getLabel() {
		return label;
	}

	@Override
	public void run(IMarker marker) {

		// Prepare
		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
		IProject project = marker.getResource().getProject();
		String buildPathPageID = "org.eclipse.jdt.ui.propertyPages.BuildPathsPropertyPage";
		
		// Get project properties dialog
		PreferenceDialog dialog = PreferencesUtil.
				createPropertyDialogOn(
						shell, 
						project, 
						buildPathPageID, 
						new String[] { buildPathPageID }, 
						Collections.EMPTY_MAP);

		// Show build path configuration
		dialog.open();
		
	}

}
